package com.wxj.bank.mq.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author shengtao
 * @Description:
 * @date 2019/02/20 12:01
 */
@Component
@RabbitListener(id = "multi",queues = "queue.original")
@SendTo("fanout.queue1")
public class MessageListener {

    @RabbitHandler
    String receive(@Payload String message , @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) throws IOException {
        System.out.println("messge:"+message);
        channel.basicAck(deliveryTag,true);
        return message;
    }

}
